package com.lancoo.ccas53.controller;

import com.lancoo.ccas53.entity.PlanTeaching;
import com.lancoo.ccas53.pojo.dto.CollegePlanDto;
import com.lancoo.ccas53.pojo.dto.CourseAndApplyDto;
import com.lancoo.ccas53.pojo.dto.PlanTeachingDto;
import com.lancoo.ccas53.pojo.vo.CourseApplyVo;
import com.lancoo.ccas53.pojo.vo.CourseType;
import com.lancoo.ccas53.pojo.vo.CourseVo;
import com.lancoo.ccas53.pojo.vo.PlanTeachingVo;
import com.lancoo.ccas53.service.PlanTeachingService;
import com.lancoo.ccas53.util.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @ClassName CoursePlanController
 * @Description TODO
 * @Author quin
 * @Date 2024/5/21 11:03
 */
@Api(tags = "开课计划控制器")
@RestController
@RequestMapping("/coursePlan")
public class CoursePlanController {

    @Autowired
    private PlanTeachingService planTeachingService;

    @ApiOperation("获取教学计划")
    @PostMapping("/getTeacherPlan")
    public ResponseObject<PlanTeachingDto> getTeacherPlan(@ApiParam(value = "教学计划", required = true) @RequestBody PlanTeachingVo param,
                                                          @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.getTeacherPlan(param, taskId));
    }

    @ApiOperation("批量设置教学计划")
    @PostMapping("/setTeacherPlan")
    public ResponseObject<Boolean> setTeacherPlan(@ApiParam(value = "操作状态", required = true) @RequestParam Integer isEnable,
                                                  @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                  @ApiParam(value = "id数组", required = true) @RequestBody List<Long> idList) {
        return ResponseObject.ofSuccess(planTeachingService.setTeacherPlan(isEnable, taskId, idList));
    }

    @ApiOperation("清空教学计划列表")
    @PostMapping("/clearTeacherPlan")
    public ResponseObject<Boolean> clearTeacherPlan(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.clearTeacherPlan(taskId));
    }

    @ApiOperation("获取教学计划对应课程")
    @GetMapping("/getCourseByTeachingPlanId")
    public ResponseObject<List<CourseVo>> getCourseByTeachingPlanId(@ApiParam(value = "基础平台教学计划id", required = true) @RequestParam String baseTeachingPlanId,
                                                                    @ApiParam(value = "1课程 2环节") @RequestParam Integer flag,
                                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.getCourseByTeachingPlanId(baseTeachingPlanId, flag, taskId));
    }

    @ApiOperation("获取课程对应教学计划")
    @GetMapping("/getTeachingPlanByCourse")
    public ResponseObject<List<PlanTeaching>> getTeachingPlanByCourse(@ApiParam(value = "基础平台课程id", required = true) @RequestParam String baseCourseId,
                                                                      @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.getTeachingPlanByCourse(baseCourseId, taskId));
    }

    @ApiOperation("获取课程类别")
    @GetMapping("/getCourseType")
    public ResponseObject<List<CourseType>> getCourseType(@ApiParam(value = "1、课程 2、环节", required = true) @RequestParam String flag,
                                                          @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.getCourseType(flag, taskId));
    }

    @ApiOperation("获取审核开课变更列表")
    @PostMapping("/getCourseAndApply")
    public ResponseObject<CourseAndApplyDto> getCourseAndApply(@ApiParam(value = "开课计划", required = true) @RequestBody CourseVo param,
                                                               @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.getCourseAndApply(param, taskId));
    }

    @ApiOperation("申请开课变更")
    @PostMapping("/dealCourseApply")
    public ResponseObject<Object> dealCourseApply(@ApiParam(value = "开课变更", required = true) @RequestBody CourseApplyVo param,
                                                  @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.dealCourseApply(param, taskId));
    }

    @ApiOperation("获取增开课程列表")
    @GetMapping("/getAddCourses")
    public ResponseObject<List<CourseVo>> getAddCourses(@ApiParam(value = "学院id", required = false) @RequestParam(required = false) String collegeId,
                                                        @ApiParam(value = "课程名模糊查询", required = false) @RequestParam(required = false) String keyword,
                                                        @ApiParam(value = "1课程 2环节", required = false) @RequestParam(required = false) Optional<Integer> flag,
                                                        @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.getAddCourses(collegeId, keyword, flag, taskId));
    }

    @ApiOperation("开课变更审核")
    @PutMapping("/examineApply")
    public ResponseObject<Boolean> examineApply(@ApiParam(value = "申请id") @RequestParam Integer applyId,
                                                @ApiParam(value = "审核意见") @RequestParam String reviewComment,
                                                @ApiParam(value = "1：通过，2：驳回") @RequestParam Integer examine,
                                                @ApiParam(value = "authorization", required = true) @RequestHeader("Authorization") String authorization,
                                                @ApiParam(value = "Userid", required = true) @RequestHeader("Userid") String userId,
                                                @ApiParam(value = "Username", required = true) @RequestHeader("Username") String userName,
                                                @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.examineApply(applyId, reviewComment, examine, authorization, userId, userName, taskId));
    }

    @ApiOperation("课程增开申请")
    @PostMapping("/addPlanCourse")
    public ResponseObject<Object> addPlanCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                @ApiParam(value = "基础平台教学计划id") @RequestParam(required = false) String baseTeachingPlanId,
                                                @ApiParam(value = "基础平台课程id") @RequestParam(required = false) String baseCourseId,
                                                @ApiParam(value = "变更说明") @RequestParam(required = false) String remark,
                                                @ApiParam(value = "1课程 2环节") @RequestParam(required = false) Integer flag) {
        return ResponseObject.ofSuccess(planTeachingService.addPlanCourse(taskId, baseTeachingPlanId, baseCourseId, remark, flag));
    }

    @ApiOperation("统计开课计划")
    @GetMapping("/publishStatistics")
    public ResponseObject<Map<String, Object>> publishStatistics(@ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                                 @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.publishStatistics(baseCollegeId, taskId));
    }

    @ApiOperation("发布开课计划")
    @PutMapping("/publishPlan")
    public ResponseObject<Boolean> publishPlan(@ApiParam(value = "基础平台学院id") @RequestHeader(required = false) String baseCollegeId,
                                               @ApiParam(value = "开课计划提交人id", required = true) @RequestHeader String userId,
                                               @ApiParam(value = "开课计划提交人姓名", required = true) @RequestHeader String userName,
                                               @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(planTeachingService.publishPlan(taskId, userId, userName, baseCollegeId));
    }

    @ApiOperation("查看提交记录")
    @GetMapping("/getPublishRecord")
    public ResponseObject<List<CollegePlanDto>> getPublishRecord(@ApiParam(value = "基础平台学院Id", required = true) @RequestParam String baseCollegeId,
                                                                 @ApiParam(value = "任务流程Id", required = true) @RequestHeader Integer taskId,
                                                                 @ApiParam(value = "1：开课计划；2确认预选课结果；3：确认教学任务 4：课表编排；5：确认选课结果", required = true) @RequestParam Integer type) {
        return ResponseObject.ofSuccess(planTeachingService.getPublishRecord(baseCollegeId, taskId, type));
    }

}
